Imports System.Windows.Forms

Public Class OptionsForm

    Private _Timeout As Integer

    Public Property Timeout() As Integer
        Get
            If optInfinite.Checked Then
                Timeout = Request.INFINITE_TIMEOUT
            Else
                Timeout = txtTimeout.Text
            End If
        End Get
        Set(ByVal value As Integer)
            txtTimeout.Text = value

            If value = Request.INFINITE_TIMEOUT Then
                optInfinite.Checked = True
            Else
                optCustom.Checked = True
            End If
        End Set
    End Property

    Private Sub ValidateTimeout()

        Dim timeout As String = txtTimeout.Text

        ErrorProvider1.Clear()

        If Not Integer.TryParse(timeout, _Timeout) Then
            ErrorProvider1.SetError(txtTimeout, "must be an positive integer")
        End If
    End Sub

    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click

        txtTimeout.Text = Request.DEFAULT_TIMEOUT
        optCustom.Checked = True

    End Sub

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub txtTimeout_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtTimeout.TextChanged

        ValidateTimeout()

    End Sub

    Private Sub optCustom_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optCustom.CheckedChanged

        txtTimeout.Enabled = True

    End Sub

    Private Sub optInfinite_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optInfinite.CheckedChanged

        txtTimeout.Enabled = False

    End Sub
End Class
